package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ThreadSafeTestServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private int count = 0;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println(this + ":" + Thread.currentThread());
		for (int i = 0; i < 5; i++) {
			System.out.println("Count = " + count);
			try {
				Thread.sleep((long)(Math.random() * 1000));
				count++;
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	
}
